//
//  MineVC.m
//  AppNew
//
//  Created by 华伟 on 2019/4/3.
//  Copyright © 2019 华伟. All rights reserved.
//

#import "MineVC.h"
#import "PersonVC.h"
#import "MyAssetsVC.h"
#import "VerifyVC.h"
#import "ContactKefu.h"
#import "StoreVC.h"
@interface MineVC ()<UINavigationControllerDelegate,UITableViewDelegate, UITableViewDataSource>{
    NSArray *dataArray;
}
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UITableView *mineTbl;
@property (weak, nonatomic) IBOutlet UIImageView *userImg;

@end

@implementation MineVC

- (void)tapTopView{
    PersonVC *vc = [PersonVC new];
    vc.hidesBottomBarWhenPushed = true;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)_initView{
    UITapGestureRecognizer *reg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTopView)];
    [_topView addGestureRecognizer:reg];
    
    _mineTbl.delegate = self;
    _mineTbl.dataSource = self;
    _mineTbl.tableFooterView = [UIView new];
    _userImg.layer.cornerRadius = 5.f;
    _userImg.layer.masksToBounds = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
    dataArray =@[
                 @[@{@"imgName":@"webicon301",@"title":@"实名认证"}],
                 @[@{@"imgName":@"qianbao-1",@"title":@"我的资产"},
                    @{@"imgName":@"weibiaoti--1",@"title":@"我的订单"},
                    @{@"imgName":@"caiwu",@"title":@"财务记录"}
                   ],
                 @[@{@"imgName":@"矩形8",@"title":@"我的推荐"},
                   @{@"imgName":@"kefu",@"title":@"联系客服"},
                   ],
                 @[@{@"imgName":@"dianpu",@"title":@"批发商管理"}]];
    [self _initView];
    
}

#pragma mark - 导航栏的代理
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isPushSelfClass = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isPushSelfClass animated:animated];
}

#pragma mark --tbl
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  50.f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 18.f;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *arr = dataArray[section];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *arr = dataArray[indexPath.section];
    NSString *nameText = [arr[indexPath.row] objectForKey:@"title"];
    NSString *imgName = [arr[indexPath.row] objectForKey:@"imgName"];
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cellId"];
    cell.imageView.image = [UIImage imageNamed:imgName];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    CGSize itemSize = CGSizeMake(25, 25);//希望显示的大小
    UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
    [cell.imageView.image drawInRect:imageRect];
    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    cell.textLabel.text = nameText;
    cell.textLabel.textColor = [UIColor colorFromHexRGB:@"333333"];
    return  cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSArray *arr = dataArray[indexPath.section];
    NSString *nameText = [arr[indexPath.row] objectForKey:@"title"];
    if ([@"我的资产"  isEqual: nameText]) {
        MyAssetsVC *vc = [[MyAssetsVC alloc] init];
        vc.hidesBottomBarWhenPushed = true;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([@"实名认证"  isEqual: nameText]) {
        
        VerifyVC *vc = [[VerifyVC alloc] init];
        vc.hidesBottomBarWhenPushed = true;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([@"我的订单"  isEqual: nameText]) {
        
        MyOrderController *vc = [[MyOrderController alloc] init];
        vc.hidesBottomBarWhenPushed = true;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([@"联系客服"  isEqual: nameText]) {
        ContactKefu *vc = [[ContactKefu alloc] init];
        vc.hidesBottomBarWhenPushed = true;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([@"批发商管理"  isEqual: nameText]) {
        StoreVC *vc = [[StoreVC alloc] init];
        vc.hidesBottomBarWhenPushed = true;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    
}

@end
